import Cookies from "js-cookie"
export default {
    state: {
        isCollapse: false,
        menu: []

    },
    mutations: {
        collapseMenu(state) {
            state.isCollapse = !state.isCollapse
        },
        setMenu(state, val){
            state.menu = val
            Cookies.set('menu', JSON.stringify(val))
        },
        clearMenu(state) {
            state.menu = []
            Cookies.remove('menu')

        },
        addMenu(state) {
            if(!Cookies.get('menu')) {
                return
            }
            // 处理menu
            const menu = JSON.parse(Cookies.get('menu'))
            state.menu = menu
            const menuArray = []
            menu.forEach(item => {
                if (item.chilren) {
                    item.chilren = item.chilren.map(item => {
                        item.component = () => import(`../views/${item.url}`)
                        return item
                    })
                    menuArray.push(...item.chilren)
                }
                else{
                    item.component = () => import(`../views/${item.url}`)
                    menuArray.push(item)
                }
            });
            // 路由动态添加
            // menuArray.forEach(item => {
                
            //     // router.addRoute('Main', item)

            //     // console.log(router);
            // })



            // router.addRoute(route)
        }
    }

}